﻿using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Web;

namespace Caltech.Service.Common
{
    public class StringValue : System.Attribute
    {
        private string _value;

        public StringValue(string value)
        {
            _value = value;
        }

        public string Value
        {
            get { return _value; }
        }

    }

    public static class StringEnum
    {
        public static string GetStringValue(Enum value)
        {
            string output = null;
            Type type = value.GetType();

            FieldInfo fi = type.GetField(value.ToString());
            StringValue[] attrs =
               fi.GetCustomAttributes(typeof(StringValue),
                                       false) as StringValue[];
            if (attrs.Length > 0)
            {
                output = attrs[0].Value;
            }

            return output;
        }
    }

    [JsonConverter(typeof(StringEnumConverter))]
    [Flags]
    public enum Reason
    {
        [StringValue("Taxi-Shipping")]
        Taxi,
        [StringValue("PO Diem")]
        Diem,
        [StringValue("Marketing Cost")]
        MaketingCost,
        [StringValue("Pay Vendor")]
        PayVendor,
        [StringValue("Office Supplies")]
        OfficeSupplies,
        [StringValue("Office Rental")]
        OfficeRental,
        [StringValue("Office Utilities")]
        OfficeUtilities,
        [StringValue("Office Maintenance")]
        OfficeMaintenance,
        [StringValue("Phone & Mobile")]
        Phone,
        [StringValue("Pay Interest")]
        PayInterest,
        [StringValue("Others")]
        Others,
        [StringValue("Taxes")]
        Taxes,
        [StringValue("Standards")]
        Standards
    }

    [JsonConverter(typeof(StringEnumConverter))]
    [Flags]
    public enum Roles
    {
        Technician = 1,
        IT = 2,
        Salesman = 4,
        Admin = 8,
        QC = 16,
        Customer = 32,
        Manager = 64
    }

    [JsonConverter(typeof(StringEnumConverter))]
    public enum Status
    {
        Tolerance = 1,
        Fail,
        Rejected,
        Limited,
        InTolerance,
        OutOfTolerance
    }

    [JsonConverter(typeof(StringEnumConverter))]
    public enum ServicePlace
    {
        Onsite = 1,
        KLLab,
        Vendor
    }

    [JsonConverter(typeof(StringEnumConverter))]
    public enum StandardLocation
    {
        SaiGon = 1,
        BacNinh,
        Vendor
    }

    [JsonConverter(typeof(StringEnumConverter))]
    public enum ProcessStatus
    {
        Waiting = 1,
        PO,
        Cancel
    }

    [JsonConverter(typeof(StringEnumConverter))]
    public enum ProcessStatusPO
    {
        Waiting = 1,
        WO,
        Cancel,
        Invoice
    }

    [JsonConverter(typeof(StringEnumConverter))]
    public enum ProcessStatusWO
    {
        Waiting = 1,
        Cert,
        Cancel
    }

    [Flags]
    public enum Areas : long
    {
        CertificateView = 1,
        CertificateCreate = 2,
        StandardView = 4,
        CustomerView = 8,
        EquipmentView = 16,
        CustomerEquipmentView = 32,
        QuoteView = 64,
        POView = 128,
        WOView = 256,
        UserView = 512,
        Config = 1024,
        CertificateEdit = 2048,
        CertificateDelete = 4096,
        StandardCreate = 8192,
        StandardEdit = 16384,
        StandardDelete = 32768,
        CustomerCreate = 65536,
        CustomerEdit = 131072,
        CustomerDelete = 262144,
        EquipmentCreate = 524288,
        EquipmentEdit = 1048576,
        EquipmentDelete = 2097152,
        CustomerEquipmentCreate = 4194304,
        CustomerEquipmentEdit = 8388608,
        CustomerEquipmentDelete = 16777216,
        QuoteCreate = 33554432,
        QuoteEdit = 67108864,
        QuoteDelete = 134217728,
        POCreate = 268435456,
        POEdit = 536870912,
        PODelete = 1073741824,
        WOCreate = 2147483648,
        WOEdit = 4294967296,
        WODelete = 8589934592,
        UserCreate = 17179869184,
        UserEdit = 34359738368,
        UserDelete = 68719476736,
        AEView = 137438953472,
        AECreate = 274877906944,
        AEEdit = 549755813888,
        AEDelete = 1099511627776,
        Report = 2199023255552,
        ProcedureView = 4398046511104,
        ProcedureCreate = 8796093022208,
        ProcedureEdit = 17592186044416,
        ProcedureDelete = 35184372088832,
        AEKToan = 70368744177664,
        AEKTTruong = 140737488355328,
        AEBGD = 281474976710656,
        AEManager = 562949953421312,
        SalesManager = 1125899906842624
    }
}